package com.lx.javasunmmrize.prototype;

/**
 * @Description 测试深拷贝
 * @Author lx
 * @Date 2021/2/27 0:21
 **/
public class PrototypeTest02 {

    public static void main(String[] args) throws CloneNotSupportedException {

        Cat2 cat = new Cat2("tom","red");
        PeopleTarget peopleTarget = new PeopleTarget();
        cat.setPeople(peopleTarget);

        //1.测试深拷贝第一种实现：重写clone方法
//        Cat2 cat2 = (Cat2) cat.clone();
//        Cat2 cat3 = (Cat2) cat.clone();
//
//        System.out.println(cat2+","+cat2.getPeople().hashCode());
//        System.out.println(cat+","+cat.getPeople().hashCode());
//        System.out.println(cat3+","+cat3.getPeople().hashCode());


        //2.测试深拷贝第2种实现：序列化
        Cat2 cat2 = (Cat2) cat.deepClone();
        Cat2 cat3 = (Cat2) cat.deepClone();

        System.out.println(cat2+","+cat2.getPeople().hashCode());
        System.out.println(cat+","+cat.getPeople().hashCode());
        System.out.println(cat3+","+cat3.getPeople().hashCode());
    }
}
